import Vue from 'vue'
import VueRouter from 'vue-router'
import index from '../views/index.vue'
import { DatePicker } from 'ant-design-vue';

Vue.use(VueRouter)

const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err);
};

Vue.use(DatePicker)

const routes = [
  {
    path: '/',
    name: 'index',
    component: index
  }, {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue'),
    meta: {
      title: "登录页"
    }
  }, {
    path: '/Cart',
    name: 'Cart',
    component: () => import('../views/cart.vue'),
    meta: {
      title: "购物车"
    }
  }, {
    path: '/detailspage',
    name: 'detailspage',
    component: () => import('../views/Detailspage.vue'),
    meta: {
      title: "商品详情页"
    }
  }, {
    path: '/ordercheck',
    name: 'ordercheck',
    component: () => import('../views/ordercheck.vue'),
    meta: {
      title: "确认订单"
    }
  }, {
    path: '/pay',
    name: 'pay',
    component: () => import('../views/pay.vue'),
    meta: {
      title: "付款页"
    }
  }
  , {
    path: '/orderdetails',
    name: 'orderdetails',
    component: () => import('../views/orderdetails.vue'),
    meta: {
      title: "订单详情页"
    }
  }
]

const router = new VueRouter({
  mode: "history",
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  }
})


export default router
